﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business.DwzFrame;
using NHibernate;
using ZLCMS.Data.Model;
using ZLCMS.Business.Util;

namespace ZLCMS.Web.SystemManage.Template.Template
{
    public partial class PageList : System.Web.UI.Page
    {
        protected FrameHelper _framePage;
        protected void Page_Load(object sender, EventArgs e)
        {
            _framePage = new FrameHelper(this);

            ParamKit.Bind("template_pages_kind", kind, null, new List<ListItem>() { ParamKit.ParamItemEx_QXZ() }, null, Request["kind"], "-1");

            int pageSize = _framePage.IsAjaxPagerPostBack ? _framePage.PageSize : 20;
            int pageIndex = _framePage.IsAjaxPagerPostBack ? _framePage.PageIndex : 1;

            using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                string sql = "from CmsPageInfo where 1=1 ";
                if (!string.IsNullOrEmpty(Request["kind"]))
                {
                    sql += " and Kind=:kind ";
                }

                IQuery query = session.CreateQuery("select count(*) " + sql);
                if (!string.IsNullOrEmpty(Request["kind"]))
                {
                    query.SetParameter("kind", Request["kind"]);
                }

                _framePage.RecordCount = Convert.ToInt32(query.UniqueResult());

                query = session.CreateQuery(sql + "order by Sort");
                if (!string.IsNullOrEmpty(Request["kind"]))
                {
                    query.SetParameter("kind", Request["kind"]);
                }
                repeater1.DataSource = query.SetMaxResults(pageSize)
                    .SetFirstResult((pageIndex - 1) * pageSize)
                    .List<CmsPageInfo>();
            }
            repeater1.DataBind();
        }


        //protected string GetContent(object item)
        //{
        //    CmsPageInfo upage = item as CmsPageInfo;
        //    string result = "<a style='color:#0C0C0C'>管理</a>";
        //    //""
        //    //if (upage.Kind != "default")
        //    {
        //        result = "<a href='/SystemManage/template/";
        //        if (upage.Kind == "list")
        //        {
        //            result += "DocList.aspx";
        //        }
        //        else
        //        {
        //            result += "DocDetail.aspx";
        //        }
        //        result += "?src=man&tempid=" + upage.Id + "'";
        //        result += " target='navTab' rel='";

        //        if (upage.Kind == "list")
        //        {
        //            result += "DocList";
        //        }
        //        else
        //        {
        //            result += "DocDetail";
        //        }
        //        result += "' title='内容管理'>内容管理</a>";

        //    }
        //    result += "&nbsp;&nbsp;";
        //    return result;

        //}
    }
}